package helperClasses;

/**
 * 
 * @author Felix Schliephacke
 * 
 */
public final class GuiHelper {

	public static final int trimSizeChoice(final String arg)
			throws NumberFormatException {
		if (arg.matches("[0-9]+x[0-9]+")) {
			final String[] temp = arg.split("x");
			if (temp.length != 2) {
				throw new NumberFormatException(
						"Size must be formatted like [0-9]+x[0-9]+");
			}
			final int one = Integer.parseInt(temp[0]);
			final int two = Integer.parseInt(temp[1]);
			if (one != two) {
				throw new NumberFormatException(
						"As this is a square, both number must be the same.");
			}
			if (!Help.isPositiveSquare(one)) {
				throw new NumberFormatException(
						"Number must be a positive square. 1, 4, 9, 16, 25, ...");
			}
			return one;
		} else {
			throw new NumberFormatException(
					"Size must be formatted like [0-9]+x[0-9]+");
		}
	}
}
